1 00:00:00,600 --> 00:00:01,730 Hello and welcome. 2 00:00:01,740 --> 00:00:10,560 In this video we are going to create javascript functionality for our game. 3 00:00:10,560 --> 00:00:17,520 The first thing I want to do is create the javascript file I've already given it a reference name here 4 00:00:17,730 --> 00:00:24,970 inside his team Mail Online 33 have called it my script Duchess. 5 00:00:25,110 --> 00:00:30,330 So I'm going to create it by clicking on the new file option clicking on file. 6 00:00:30,990 --> 00:00:46,120 And then you save this new file to save as hallum going to save it as my script. 7 00:00:46,310 --> 00:00:47,180 Yes. 8 00:00:47,460 --> 00:00:48,900 So my script. 9 00:00:49,110 --> 00:00:50,210 Yes. 10 00:00:50,630 --> 00:00:54,660 So it's called my script which is going to my index. 11 00:00:54,720 --> 00:00:58,930 You can see the name of the same script. 12 00:00:59,200 --> 00:00:59,700 Yes. 13 00:00:59,940 --> 00:01:05,290 It's important that the name you linked it to in your email file. 14 00:01:05,400 --> 00:01:10,330 How can you make sure it's the name of the outro farm if not it will not work. 15 00:01:10,350 --> 00:01:15,760 The first thing I want to do is add some constant variables. 16 00:01:15,900 --> 00:01:24,010 These are the variable a constant physically variable that should not change in value. 17 00:01:24,330 --> 00:01:34,350 Okay so we've created a constancy code halls and set it to court documents or query select all and pass 18 00:01:34,380 --> 00:01:36,460 to the class. 19 00:01:36,770 --> 00:01:42,260 Doctor here followed by the name is a class so passed to the class hall. 20 00:01:42,900 --> 00:01:46,820 So these classes have already been defined inside his team. 21 00:01:46,860 --> 00:01:54,130 Also I go into the hastier mail you can see we've got a class here or two score of the class called 22 00:01:54,350 --> 00:01:55,110 Hall. 23 00:01:55,220 --> 00:01:57,170 And the class called more. 24 00:01:57,390 --> 00:02:07,880 So these are the classes I'm referring to inside this javascript document dot query select all or both 25 00:02:07,910 --> 00:02:19,890 physically same method this query select or is a method that returns all the elements in the document 26 00:02:20,370 --> 00:02:28,350 that matches is specified synthesis select or select. 27 00:02:28,500 --> 00:02:37,980 The next thing I want to do is create a function that all create a random time for the all to pop out 28 00:02:38,190 --> 00:02:39,220 of the hall. 29 00:02:39,540 --> 00:02:41,030 So I'm just going to. 30 00:02:41,040 --> 00:02:43,060 This is a function of defined here. 31 00:02:43,150 --> 00:02:51,270 I've called it a function called random time random time so it would generate random time and have passed 32 00:02:51,270 --> 00:02:52,270 it. 33 00:02:52,520 --> 00:02:53,400 And Max. 34 00:02:53,400 --> 00:03:01,600 These are functions on their on methot So this will return the maths stop round maths round beasley's 35 00:03:01,720 --> 00:03:08,020 use to round up their numbers to the nearest term whole integer number. 36 00:03:08,280 --> 00:03:10,570 And this is a maths random. 37 00:03:10,620 --> 00:03:17,790 This will randomly generate numbers and will use the mouse thought round to round up the numbers to 38 00:03:17,790 --> 00:03:20,450 the nearest whole integer. 39 00:03:20,730 --> 00:03:24,160 So we're multiplying the random number generator. 40 00:03:24,540 --> 00:03:32,940 And by the max maximum number minus the minimum number plus the minimum number. 41 00:03:32,940 --> 00:03:37,070 So these are all different functions of methods. 42 00:03:37,290 --> 00:03:45,380 So once the random numbers generated were play the max minus mean Plus mean someone to say that so I 43 00:03:45,400 --> 00:03:50,430 can see how this works are going to run this inside the console. 44 00:03:50,550 --> 00:03:59,250 So this is a project and will not open up the index or to email and click on 12 on the keyboard to open 45 00:03:59,250 --> 00:04:00,610 up the console. 46 00:04:01,110 --> 00:04:07,410 So now that I've got the console open I'm going to run this function called round. 47 00:04:07,500 --> 00:04:13,970 Time inside here and then pass it in minimum and maximum time. 48 00:04:14,010 --> 00:04:18,150 So here I am just going to type it inside the console typing random 49 00:04:20,730 --> 00:04:34,510 time and then decided this is the minimum value would be 20 milliseconds and the maximum will be 2 seconds. 50 00:04:34,560 --> 00:04:39,980 All right so now if I press pentair he should randomly generate a time taken see it. 51 00:04:39,990 --> 00:04:46,890 Thus the one random time I do again and again and again you can see. 52 00:04:46,890 --> 00:04:54,120 So we know we've got that functionality working next and I want to do is create on another function. 53 00:04:54,250 --> 00:04:59,780 Is going to be a random function that will determine the random Hall this at all. 54 00:05:00,000 --> 00:05:08,810 Wells So to determine the random halls from which the mall will pick his head or pop out from I have 55 00:05:08,880 --> 00:05:17,680 added the function that all randomly specify the holes from where the moles was going to pop up from. 56 00:05:17,750 --> 00:05:22,160 So it's called the function random hall and I've passed in the halls. 57 00:05:22,340 --> 00:05:28,850 Okay so this was actually the holes and then line 10 here have got a variable chord index. 58 00:05:28,850 --> 00:05:36,740 It's a constant that means when unexpected to change I have set that course to the max top floor and 59 00:05:36,740 --> 00:05:43,310 then we've got the maths at random as well so it would generate a similar process to this random time 60 00:05:43,850 --> 00:05:49,650 masten Random we generate the random time and then we've got the master top floor. 61 00:05:49,730 --> 00:05:52,410 Well be run that opted in. 62 00:05:52,820 --> 00:06:02,960 So the last thought flow function will return the largest integer less than or equal to a given number 63 00:06:03,660 --> 00:06:10,970 and the mouse or random generates the random number and then we multiply that by the holes left. 64 00:06:11,180 --> 00:06:17,260 So we know we have six altes so that's represented by the lente and here again. 65 00:06:17,360 --> 00:06:25,180 A constant variable called hall setting to cause today calls and then inside the square brackets are 66 00:06:25,190 --> 00:06:34,850 passing in this variable index So the index basically refers to the array of holds the first index would 67 00:06:34,850 --> 00:06:38,480 be zero and then 1 2 3 4 5 and so on. 68 00:06:38,690 --> 00:06:46,790 Okay so that's the index so this line 13 here is just so constant log to that I can test it to make 69 00:06:46,790 --> 00:06:55,520 sure that it is randomly assigning the holes to all the holes that the mall is going to pop up from 70 00:06:55,910 --> 00:07:01,880 someone and say this and open up the document and will go inside the console and quickly check this 71 00:07:01,880 --> 00:07:09,570 out so I open up the hasty email file and also clicked on F 12 for my cable to open up this console. 72 00:07:09,740 --> 00:07:16,260 So here all I need to do is type in the name of the function which is run on whole. 73 00:07:17,450 --> 00:07:22,240 And I am one of past holes. 74 00:07:22,400 --> 00:07:27,720 Had just press pent up an issue you can see is generated around who's generated random all. 75 00:07:27,760 --> 00:07:30,520 Number two try again. 76 00:07:30,680 --> 00:07:36,180 Give me all number one this time Hole number for this time on number 5. 77 00:07:36,200 --> 00:07:44,450 Excellent So this is what I wanted to add for the holes to be randomly assigned where the mall is going 78 00:07:44,450 --> 00:07:50,780 to pop out from one of the things that may occur or when you generate in random numbers is that you 79 00:07:50,780 --> 00:07:55,170 may get the same number generated twice or more. 80 00:07:55,340 --> 00:08:04,070 So what we want to do we don't want we want to avoid that so that we can have different calls assigned 81 00:08:04,160 --> 00:08:05,430 different numbers. 82 00:08:05,570 --> 00:08:14,740 So one way to do I need to put a conditional statement in that will prevent this same all from getting 83 00:08:14,750 --> 00:08:16,010 the same number. 84 00:08:16,260 --> 00:08:21,240 Okay all right so did the conditional statement which is this block here. 85 00:08:21,410 --> 00:08:28,730 So basically I am saying what I need to do is define key variable or peer. 86 00:08:29,500 --> 00:08:31,820 So I go online for here. 87 00:08:31,820 --> 00:08:39,940 I've just added a statement here lets statement and give it the value of last hole. 88 00:08:40,000 --> 00:08:49,160 The little statement basically declares a block scope local variable so that each option only has to 89 00:08:49,220 --> 00:08:57,830 initialize for the value to be active so it allows you to declare variables that are limited in scope 90 00:08:58,040 --> 00:09:07,160 to the block statement or the expression on which it is used in a way it's different from the variable 91 00:09:07,240 --> 00:09:17,200 keyword which defines variable globally or locally to an entire function regardless of the block scope. 92 00:09:17,360 --> 00:09:24,620 So now that we've defined the little statement here on on line for now implemented it here. 93 00:09:24,620 --> 00:09:30,420 So basically I'm saying if the hall is strictly equal to the last hole. 94 00:09:30,770 --> 00:09:36,700 Okay that if the numbers are the same we want to log this message on the console. 95 00:09:36,860 --> 00:09:39,990 That's the same number and what it will do it. 96 00:09:40,000 --> 00:09:48,020 We don't really render this function called random hole and regenerate in New numbers so the objective 97 00:09:48,020 --> 00:09:52,370 of this we don't want the same halls to have the same number. 98 00:09:52,790 --> 00:09:57,500 To warn them to be around omni generators or where there's the same number. 99 00:09:57,590 --> 00:09:59,730 Got this written return here. 100 00:09:59,980 --> 00:10:07,610 Reach render this function it calls it function again to render a mother random number for that call 101 00:10:07,930 --> 00:10:13,560 where the last no had for example we've had the last number generator for a horse too. 102 00:10:13,800 --> 00:10:22,460 And you generate two again instead of randomly assigned him that is to really render this function to 103 00:10:22,520 --> 00:10:24,510 create a new random number. 104 00:10:24,740 --> 00:10:32,500 And here we are calling this here this left statement and we set it up to YOU course to the whole day 105 00:10:32,660 --> 00:10:38,820 and we are now returning all that has been assigned randomly. 106 00:10:39,140 --> 00:10:46,040 So that is it for this part of the ledger on one side of this and then part two. 107 00:10:46,040 --> 00:10:51,850 We will try and complete the rest of the script for this project. 108 00:10:51,890 --> 00:10:52,980 Thank you for watching. 109 00:10:53,030 --> 00:10:54,150 And bye for now.